﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Ccit.OA.SystemDoc
{
    public partial class SystemDoc_codemanage_view : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                _hidsQuery.Value = "";
                this._hidCodeID.Value = (null != Request.QueryString["CodeID"]) ? Request.QueryString["CodeID"].ToString() : "";                
            }
            InitPage();
        }
        private void InitPage()
        {
            if(_hidCodeID.Value!="")
            {
                SystemDocBLL Bll = new SystemDocBLL();
                DataSet dSet = Bll.GetCodeManage(_hidCodeID.Value, _hidsQuery.Value);
                if(dSet.Tables[0].Rows.Count>0)
                {
                    dgMain.DataSource = dSet;
                }
                else
                {
                    dgMain.DataSource = null;
                }
                dgMain.DataBind();
                Bll = null;
            }
        }

        protected void dgMain_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
            string sRecid = dgMain.GetRowValues(e.VisibleIndex, "Number").ToString();
            HtmlAnchor lnbDel = (HtmlAnchor)dgMain.FindRowCellTemplateControl(e.VisibleIndex, null, "lnbDel");
            lnbDel.Attributes["href"] = "javascript:doDel('" + sRecid + "')";
        }
        #region Ajax Methods
        /// <summary>
        /// get budge 
        /// </summary>
        /// <param name="assetId"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string DoOperate(string sNumber)
        {
            SystemDocBLL Bll = new SystemDocBLL();
            List<string> lstResult = Bll.DoOperateCodeManage(sNumber, "");
            var newObj = new { resultSign = lstResult[0] };
            string serExpr = JavaScriptConvert.SerializeObject(newObj);
            Bll = null;
            newObj = null;
            return serExpr;
        }
        #endregion

        protected void lnbQuery_Click(object sender, EventArgs e)
        {
            InitPage();
        }
    }
}
